<?php

namespace app\store\controller;

use app\common\service\Finance as ServiceFinance;
use think\Cache;
use think\cache\driver\Redis;
use think\Db;
use think\Request;

/**
 * 商品管理控制器
 * Class Finance
 * @package app\store\controller
 */
class Finance extends Controller
{
    /**
     * 
     * 主页
     * 
     */
    public function index()
    {
        $list = Db::query("SELECT FROM_UNIXTIME(create_time,'%Y') AS YY FROM `yoshop_orders` where `pay_status` = 2 GROUP BY YY ");
        
        return $this->fetch('index',compact('list'));

    }
    /**
     *  数据
     */
    public function data()
    {
        $curr_year = date('Y');
        $year = $this->request->param('year');
        if(empty($year)){
            $year = $curr_year;
        }
        
        $data = new ServiceFinance();
        $data->test2();
        // $redis = new Redis();
        
        // $list = $redis->get('finance');
        
        $list = Cache::store('redis')->get('finance');
        $list = json_decode($list,true);
    
        $arr = [];
        foreach($list as $k=>$v){
            $arr[$v['yy']][] = $v;            
        }
        if(!array_key_exists($year,$arr)){
            return false;
        }
        return json($arr[$year]);
    }
    
}
